<?php
/**
 * Copyright 2011 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 * @author Nadim Ratani <nratani@google.com>
 * @version 1.0
 */
include "jwt.php";
include "config.php";

$order = array(
  "drink" => $_POST["orderDescription"],
  "size" => $_POST["size"],
  "milk" => $_POST["milk"],
  "pickup" => $_POST["pickup"],
  "total" => $_POST["formTotal"]
);

// Decode and verify the full wallet response JWT
$full_wallet_response = JWT::decode($_POST["fullWalletJWT"], $Config["signing_key"]);
$pay = $full_wallet_response->selection->pay;

// Create a transaction status notification JWT
$transaction_status_notification = array(
  "aud" => "Google",
  "iat" => (int)date("U"),
  "iss" => $Config["iss"],
  "google_transaction_id" => $full_wallet_response->google_transaction_id,
  "status" => "SUCCESS",
  "typ" => "google/paymentexpress/v1/transactionstatus");
$transaction_status_notification_jwt = JWT::encode($transaction_status_notification, $Config["signing_key"]);
?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Wallet Baristas</title>
  <link rel="stylesheet" type="text/css" href="css/style.css" media="screen">
  <script type="text/javascript"
        language="javascript"
        src="<?php echo $Config["jsURL"] ?>">
  </script>
  <script type="text/javascript">
    window.onload = function(){
      goog.wallet.notifyTransactionStatus("<?php echo $transaction_status_notification_jwt ?>");
    }
  </script>
</head>
<body>
  <div id="header">
    <h1>Wallet Baristas</h1>
  </div>
  
  <h2>Receipt</h2>
  <div id="formatBar">
  	<p>Your order has been placed!  Thank you for your order.</p>
    <div class="offset"><b>Purchase Details</b></div>
    <br />
    <div class="offset"><?php echo $order["drink"] ?></div>
    <div class="offset"><b>Total: </b><?php echo $order["total"] ?></div>
  </div>
  <h2>Payment Details</h2>
  <h4>Card Details</h4>
  <div id="formatBar">
    <div class="offset"><b>name: </b><?php echo $pay->payment_instrument->billing_address->name ?></div>
    <div class="offset"><b>card name: </b><?php echo $pay->payment_instrument->descriptive_name ?></div>
    <div class="offset"><b>type: </b><?php echo $pay->payment_instrument->type ?></div>
    <div class="offset"><b>expiration: </b><?php echo $pay->payment_instrument->expiration_month ?>/<?php echo $pay->payment_instrument->expiration_year ?></div>
    <!-- <div class="offset"><b>card number: </b><?php echo $pay->payment_instrument->full_card_number->field_data ?></div> -->
    <!-- <div class="offset"><b>card cvv: </b><?php echo $pay->payment_instrument->cvc->field_data ?></div> -->
  </div>
</body>
</html>
